package com.lswms.modules.lswms.dao.WCS;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;

@Mapper
public interface WCSDao  {

	@Select(value =" select a.sku,b.descr,b.effectlife,b.warningdays ,sum(qty) qty "
			+ " from lswms_inventory a join lswms_sku b  on a.sku = b.sku "
			+ " join lswms_lot c  on  a.lot = c.lot  "
			+ "	and ((c.lot1 is not null  and c.lot1 + b.effectlife-warningdays < GETDATE()  )  or ( c.lot2 is not null  and  c.lot2-warningdays < GETDATE() )) "
			+ " ${ew.customSqlSegment}"
			)
	List<Map<String, Object>> getEarlyWarning(@Param(Constants.WRAPPER)QueryWrapper wrapper);

	@Select(value="select a.sku,b.descr,b.safetyqty ,sum(qty) qty "
			+ "from lswms_inventory a join lswms_sku b  on  a.sku = b.sku  "
			+ "	join  lswms_lot c  on  a.lot = c.lot and c.lot10 <>1 "
		
			+"  ${ew.customSqlSegment} ")
	List<Map<String, Object>> getSafetyStock(@Param(Constants.WRAPPER)QueryWrapper wrapper);

	@Select(value="select DVC_NO,status, case when status='1' then N'正常' else N'停用' end statusstr from WCS_DDJ order by DVC_NO ")
	List<Map<String, Object>> getDDJ();

	@Update(value=" update WCS_DDJ set status= #{status} where DVC_NO= #{dvc_No} ")
	void changeDDJStatus(String dvc_No, String status);

	@Select(value="select id,task_id,task_type,task_status,material_code,material_name,priority,type,locate_from,locate_to,"
			+ "locate_lane_no,lot_code,tary_from,tary_to,qty,start_time,end_time,uuid,remark,creator,create_date,updater,"
			+ "update_date,GETX,GETY,GETZ,PUTX,PUTY,PUTZ,fromlane,tolane,to_work_no,export from tb_task order by id ")
	List<Map<String, Object>> getWCSTask();

	@Select(value="select id,task_id,task_type,task_status,material_code,material_name,priority,type,locate_from,locate_to,"
			+ "locate_lane_no,lot_code,tary_from,tary_to,qty,start_time,end_time,uuid,remark,creator,create_date,updater,"
			+ "update_date,GETX,GETY,GETZ,PUTX,PUTY,PUTZ,fromlane,tolane,to_work_no,export "
			+ "from tb_task where task_id= #{taskid} ")
	List<Map<String, Object>> getWCSTaskBy(String taskid);

	@Update(value=" update tb_task set task_status=#{status},manual=1 where task_id= #{taskid} ")
	void updateWCSTaskStatus(String taskid, String status);
	
	@Delete(value=" delete from  tb_task where task_id= #{taskid} ")
	void deleteWCSTaskBy(String taskid);


}
